package com.wyc.filter;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

/**
 * @author
 */
@Activate(group = {CommonConstants.CONSUMER})
public class TransportIpFilter implements Filter {

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        if(invoker.getInterface().getName().equals("com.wyc.service.HelloService") ||
                invoker.getInterface().getName().equals("com.wyc.service.GoodByeService")){
            Object[] arguments = invocation.getArguments();
            if(arguments.length == 1){
                RpcContext.getContext().setAttachment("hostAddress", (String) arguments[0]);
            }
        }
        return invoker.invoke(invocation);
    }
}
